home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / misc / football / exec / stats.rexx < prev    next >
OS/2 REXX Batch file  |  1999-11-29  |  15KB  |  572 lines

  1. /* ***********************************************************************
  2.  
  3.    STATS PROGRAM FOR FOOTBALL REXX SUITE
  4.   ---------------------------------------
  5.                    Copyright  Mark Naughton 1996
  6.  
  7.  
  8. Version    Date     History
  9. --------------------------------------------------------------------------
  10.  1.0       270996   First release.
  11.            300996   Amended display for Performance. Tidied some code and
  12.                     added an error message.
  13.  1.1       111196   Added to Football as a callable component. Amended for
  14.                     different leagues. Fixed bug where if one match was
  15.                     played, the performance wasn't shown. Fixed bug where
  16.                     the longest performance record wasn't correctly done.
  17.                     Removed messages.
  18.            131196   Added checks for files - if not found, exits without
  19.                     a message.
  20.            181196   Fixed bug where if 3 matches had been played, the
  21.                     performance was not printed correctly as the number
  22.                     of iterations required to format it was wrong.
  23.            201196   Added code to display home and away performance.
  24.            211196   Updated and tidied the display.
  25.  1.2       110497   Added code to support Points_Per_Goals.
  26.            151297   Tidied display.
  27.  1.3       190499   Added clean sheet to stats and added Key. Remoulded
  28.                     the display.
  29.  1.4       270699   Reorganized code into sections instead one great big
  30.                     conditional IF. Added code to display highest/lowest
  31.                     attendances and top goal scorers.
  32.            250899   Added error msg to file check.
  33.            280899   Converted to use locale. Some error messages, before
  34.                     reading the locale, will still be in English. Top
  35.                     goal scorers do not show own goals.
  36.  
  37.  
  38. **************************************************************************
  39.  
  40. Procedure
  41. ---------
  42.  
  43. 1. Check files exist. Read Teams.df datafile and store teams and points.
  44. 2. Close file. Prompt user for a team to display fixtures for.
  45. 3. Display data and open 'Teams.sflearn'.
  46. 4. Read data about matches that the selected team has played and store it.
  47.    This applies to both home and away matches even though the data is on
  48.    different panels.
  49. 5. Close file and then display data.
  50. 6. Calculate record and performance and then display these. Then exit...
  51.  
  52. ************************************************************************** */
  53. PARSE ARG league_stuff
  54.  
  55. version      = 1
  56. input_file   = '.df'
  57. input2_file  = '.sflearn'
  58. title        = '*LEAGUE_NAME='
  59. points_win   = '*POINTS_PER_WIN='
  60. points_drw   = '*POINTS_PER_DRW='
  61. points_lse   = '*POINTS_PER_LSE='
  62. points_gls   = '*POINTS_PER_GLS='
  63. separator    = '*'
  64. teams.       = '???'
  65. counter      = 0
  66. not_played   = '__   __'
  67. hplay        = 0
  68. hwin         = 0
  69. hdraw        = 0
  70. hloss        = 0
  71. hgoals       = 0
  72. hagoals      = 0
  73. hpts         = 0
  74. hcls         = 0
  75. aplay        = 0
  76. awin         = 0
  77. adraw        = 0
  78. aloss        = 0
  79. agoals       = 0
  80. aagoals      = 0
  81. apts         = 0
  82. acls         = 0
  83. ptsgls       = 0
  84.  
  85. home_def     = '*HG='
  86. away_def     = '*AG='
  87. attd_def     = '*ATD='
  88. goalsc.      = '???'
  89. goalscorers. = '???'
  90. goalss.      = '???'
  91. gscount      = 0
  92. gscounter    = 0
  93. hamatch      = ""
  94. hanum        = 0
  95. lamatch      = ""
  96. lanum        = 999999999
  97.  
  98.  
  99. parse var league_stuff league_file search_team
  100. league_file = "Data/" || league_file
  101.  
  102. if open(datafile,"Data/Football.locale",'r') then do
  103.    line = readln(datafile)
  104.    locdir = strip(line)
  105.    close(datafile)
  106. end
  107. else do
  108.    say
  109.    say "ERROR :    (Stats)"
  110.    say
  111.    say "Cannot read 'Data/Football.locale' for the locale settings."
  112.    exit
  113. end
  114.  
  115. dfordir = locdir"Football.locale_data"
  116. locdir = locdir"Exec/Stats.data"
  117.  
  118. if open(datafile,"ENV:FootballRXPath",'r') then do
  119.    line = readln(datafile)
  120.    rxdir = strip(line)
  121.    close(datafile)
  122. end
  123. else
  124.    rxdir = "SYS:Rexxc/"
  125.  
  126. if exists(locdir) > 0 then do
  127.   address command rxdir'rx 'locdir
  128.   VarCount = getclip('VarCount')
  129.   do i = 1 to VarCount
  130.     interpret getclip('var.'i)
  131.   end
  132. end
  133. else do
  134.    say
  135.    say "ERROR :    (Stats)"
  136.    say
  137.    say "Cannot find '"locdir"' to read locale settings."
  138.    exit
  139. end
  140.  
  141. if exists(dfordir) > 0 then do
  142.   address command rxdir'rx 'dfordir
  143.   VarCount = getclip('VarCount')
  144.   do i = 1 to VarCount
  145.     interpret getclip('var.'i)
  146.   end
  147. end
  148. else do
  149.    say
  150.    say "ERROR :    (Stats)"
  151.    say
  152.    say "Cannot find '"dfordir"' to read date locale settings."
  153.    exit
  154. end
  155.  
  156. if exists(league_file || input_file) = 0  then do
  157.    say
  158.    say st_error
  159.    say
  160.    say st_one"'"league_file||input_file"'."
  161.    exit
  162. end
  163.  
  164. if exists(league_file || input2_file) = 0 then do
  165.    say
  166.    say st_error
  167.    say
  168.    say st_one"'"league_file||input2_file"'."
  169.    exit
  170. end
  171.  
  172. if open(datafile,league_file || input_file,'r') then do
  173.    do while ~eof(datafile)
  174.       line = readln(datafile)
  175.       if pos(title,line) > 0 then       league_title = delstr(line,1,13)
  176.       if pos(points_win,line) > 0 then  ptswin=delstr(line,1,16)
  177.       if pos(points_drw,line) > 0 then  ptsdrw=delstr(line,1,16)
  178.       if pos(points_lse,line) > 0 then  ptslse=delstr(line,1,16)
  179.       if pos(points_gls,line) > 0 then  ptsgls=delstr(line,1,16)
  180.       if pos(separator,line) = 0 then do
  181.          line = strip(line)
  182.          if counter = 0 then do
  183.             teams.1 = line
  184.             counter = 1
  185.          end
  186.          else do
  187.             counter       = counter + 1
  188.             teams.counter = line
  189.          end
  190.       end
  191.    end
  192.    close(datafile)
  193. end
  194. else do
  195.    say
  196.    say st_error
  197.    say
  198.    say st_two"'"league_file || input_file"'."
  199. end
  200.  
  201.  
  202. sel=-1
  203. search_team = strip(search_team)
  204. do i=1 to counter
  205.    if pos(search_team,teams.i) > 0 then sel = i
  206. end
  207.  
  208. if sel < 1 then do
  209.    say
  210.    say st_error
  211.    say
  212.    say st_three"'"search_team"'"st_four
  213.    exit
  214. end
  215.  
  216. say
  217. say center(st_txt1"'"league_title"'",78)
  218. say "-------------------------------------------------------------------------------"
  219. say
  220. say
  221. say st_txt2""upper(teams.sel)
  222. say
  223. say
  224. say
  225. matches = 0
  226. lrecord = ''
  227. awayperf= ''
  228. homeperf= ''
  229. if open(datafile,league_file || input2_file,'r') then do
  230.    do while ~eof(datafile)
  231.       line = readln(datafile)
  232.       if pos(separator,line) = 0 then do
  233.          if pos(not_played,line) = 0 then do
  234.             home_team = strip(substr(line,1,30))
  235.             goals_for = substr(line,32,2)
  236.             goals_aga = substr(line,37,2)
  237.             away_team = strip(substr(line,41,30))
  238.             strng     = strip(teams.sel)
  239.  
  240.             if strng = home_team then do
  241.                if goals_aga = 0 then
  242.                   hcls = hcls + 1
  243.                if goals_for > goals_aga then do
  244.                   hwin = hwin + 1
  245.                   ltemp = st_txtq
  246.                   hpts = hpts + ptswin
  247.                end
  248.                if goals_for = goals_aga then do
  249.                   hdraw = hdraw + 1
  250.                   ltemp = st_txtr
  251.                   hpts = hpts + ptsdrw
  252.                end
  253.                if goals_for < goals_aga then do
  254.                   hloss = hloss + 1
  255.                   ltemp = st_txts
  256.                   hpts = hpts + ptslse
  257.                end
  258.                lrecord = insert(ltemp,lrecord,matches+1,1)
  259.                homeperf= insert(ltemp,homeperf,hplay+1,1)
  260.                hgoals  = hgoals + goals_for
  261.                hagoals = hagoals+ goals_aga
  262.                hplay   = hplay + 1
  263.                matches = matches + 1
  264.                hpts    = hpts + (goals_for * ptsgls)
  265.             end
  266.             if strng = away_team then do
  267.                if goals_for = 0 then
  268.                   acls = acls + 1
  269.                if goals_for > goals_aga then do
  270.                   aloss = aloss + 1
  271.                   ltemp = st_txts
  272.                   apts  = apts + ptslse
  273.                end
  274.                if goals_for = goals_aga then do
  275.                   adraw = adraw + 1
  276.                   ltemp = st_txtr
  277.                   apts  = apts + ptsdrw
  278.                end
  279.                if goals_for < goals_aga then do
  280.                   awin  = awin + 1
  281.                   ltemp = st_txtq
  282.                   apts  = apts + ptswin
  283.                end
  284.                lrecord = insert(ltemp,lrecord,matches+1,1)
  285.                awayperf= insert(ltemp,awayperf,aplay+1,1)
  286.                agoals  = agoals + goals_aga
  287.                aagoals = aagoals+ goals_for
  288.                aplay   = aplay + 1
  289.                matches = matches + 1
  290.                apts    = apts + (goals_aga * ptsgls)
  291.             end
  292.          end
  293.       end
  294.    end
  295.    close(datafile)
  296. end
  297. else do
  298.    say
  299.    say st_error
  300.    say
  301.    say st_two"'"league_file || input2_file"'."
  302.    exit
  303. end
  304.  
  305. /* code to check for top goal scorer and attendances */
  306.  
  307. j = 0
  308. if open(datafile,league_file || input2_file,'r') then do
  309.    do while ~eof(datafile)
  310.       line = readln(datafile)
  311.       if pos(separator,line) = 0 then do
  312.          j = 0
  313.          home_team = strip(substr(line,1,30))
  314.          goals_for = substr(line,32,2)
  315.          goals_aga = substr(line,37,2)
  316.          away_team = strip(substr(line,41,30))
  317.          strng     = strip(teams.sel)
  318.  
  319.          if strng = home_team then
  320.             j = 1
  321.          if strng = away_team then
  322.             j = 2
  323.       end
  324.       else do
  325.          if j > 0 then do
  326.             if pos(home_def,line) > 0 & j = 1 then do
  327.                gscount = gscount + 1
  328.                parse var line "*HG=" goalsc.gscount
  329.             end
  330.             if pos(away_def,line) > 0 & j = 2 then do
  331.                gscount = gscount + 1
  332.                parse var line "*AG=" goalsc.gscount
  333.             end
  334.             if pos(attd_def,line) > 0 then do
  335.                parse var line "*ATD=" attend
  336.                if attend > hanum then do
  337.                   hanum = attend
  338.                   hamatch = home_team""txt_versus""away_team
  339.                end
  340.                if attend < lanum then do
  341.                   lanum = attend
  342.                   lamatch = home_team""txt_versus""away_team
  343.                end
  344.             end
  345.          end
  346.       end
  347.    end
  348.    close(datafile)
  349. end
  350. else do
  351.    say
  352.    say st_error
  353.    say
  354.    say st_two"'"league_file || input2_file"'."
  355.    exit
  356. end
  357.  
  358. if gscount > 0 then do
  359.    do gsc=1 to gscount
  360.       if pos("(P)",goalsc.gsc) > 0 then do
  361.          kl = pos("(P)",goalsc.gsc)
  362.          goalsc.gsc = delstr(goalsc.gsc,kl,3)
  363.       end
  364.       klk = words(goalsc.gsc)
  365.       if datatype(word(goalsc.gsc,klk)) = "NUM" then
  366.          goalsc.gsc = delword(goalsc.gsc,klk,1)
  367.    end
  368.    do gsc=1 to gscount
  369.       name = goalsc.gsc
  370.       notin = 0
  371.       do ii=1 to gscounter
  372.          if pos(name,goalscorers.ii) > 0 then do
  373.             goalss.ii = goalss.ii + 1
  374.             notin = 1
  375.          end
  376.       end
  377.       if notin = 0 then do
  378.          gscounter = gscounter + 1
  379.          goalscorers.gscounter = name
  380.          goalss.gscounter  = 1
  381.       end
  382.    end
  383. end
  384.  
  385. if gscounter > 1 then do
  386.    if open(datafile,"RAM:Football.tempcup",'w') then do
  387.       do ii=1 to gscounter
  388.          if pos("(og)",goalscorers.ii) = 0 then
  389.             writeln(datafile,left(goalss.ii,4)"     "goalscorers.ii)
  390.       end
  391.       close(datafile)
  392.    end
  393.    else do
  394.       say
  395.       say st_error
  396.       say
  397.       say st_txt3
  398.       exit
  399.    end
  400.    address command 'Exec/Sort4Chars '
  401. end
  402.  
  403. say
  404. if matches = 0 then do
  405.    say st_txt4
  406.    say
  407. end
  408. else do
  409.    say st_txt5
  410.    say
  411.    say st_txt6
  412.    say "  --------------------------------------     --------------------------------------"
  413.    h1 = "  "left(hplay,3)" "
  414.    h2 = left(hwin,3)" "
  415.    h3 = left(hdraw,3)" "
  416.    h4 = left(hloss,3)" "
  417.    h5 = left(hgoals,4)" "
  418.    h6 = left(hagoals,4)" "
  419.    h7 = left(hpts,6)"      "
  420.    h8 = left(hcls,4)" "
  421.    a1 = left(aplay,3)" "
  422.    a2 = left(awin,3)" "
  423.    a3 = left(adraw,3)" "
  424.    a4 = left(aloss,3)" "
  425.    a5 = left(agoals,4)" "
  426.    a6 = left(aagoals,4)" "
  427.    a7 = left(apts,6)
  428.    a8 = left(acls,4)" "
  429.    say h1||h2||h3||h4||h8||h5||h6||h7||a1||a2||a3||a4||a8||a5||a6||a7
  430.    say
  431.    say
  432.    say
  433.    say
  434.    say
  435.    re  = 0
  436.    lre = 0
  437.    do i=1 to matches+1
  438.       if substr(lrecord,i,1) = st_txtq then re = re + 1
  439.       if substr(lrecord,i,1) = st_txtr then re = re + 1
  440.       if substr(lrecord,i,1) = st_txts then do
  441.          if re > lre then lre = re
  442.          re = 0
  443.       end
  444.    end
  445.    if lre = 0 then lre = re
  446.  
  447.    lrecord = strip(lrecord)
  448.    countr = (matches * 2) - 1
  449.    if matches > 8 then do
  450.       lrecord = right(lrecord,8)
  451.       countr  = 15
  452.    end
  453.    call format_perf(lrecord,countr)
  454.    if countr = 1 then ptemp = lrecord
  455.    if matches < 9 then
  456.       say st_txt7""matches""st_txt8""ptemp
  457.    else
  458.       say st_txt9""ptemp
  459.  
  460.    homeperf=strip(homeperf)
  461.    hcountr = (hplay * 2) - 1
  462.    if hplay > 8 then do
  463.       homeperf = right(homeperf,8)
  464.       hcountr  = 15
  465.    end
  466.    call format_perf(homeperf,hcountr)
  467.    if hplay = 1 then ptemp = homeperf
  468.    say
  469.    say st_txt0""ptemp
  470.  
  471.    awayperf=strip(awayperf)
  472.    acountr = (aplay * 2) - 1
  473.    if aplay > 8 then do
  474.       awayperf = right(awayperf,8)
  475.       acountr  = 15
  476.    end
  477.    call format_perf(awayperf,acountr)
  478.    if aplay = 1 then ptemp = awayperf
  479.    say
  480.    say st_txta""ptemp
  481.    say
  482.    say
  483.    say
  484.    say st_txtb""re""st_txtc
  485.    say st_txtd""lre""st_txtc
  486.    say
  487.    say
  488.    if hanum > 0 then do
  489.       say st_txte""left(hanum,6)""st_txtf""hamatch
  490.       say
  491.    end
  492.    if lanum ~= 999999999 then do
  493.       say st_txtg""left(lanum,6)""st_txtf""lamatch
  494.       say
  495.    end
  496.    if gscounter > 0 then do
  497.       say
  498.       say st_txth
  499.       say st_txti
  500.       say
  501.       say "     "st_txtt
  502.       st_line = ""
  503.       do dp=1 to length(st_txtt)+3
  504.          st_line = st_line"-"
  505.       end
  506.       say "  "st_line
  507.       say
  508.       if gscounter = 1 then do
  509.          say left(goalss.1,4)"     "goalscorers.1
  510.          say
  511.       end
  512.       else do
  513.          ii = 0
  514.          if open(datafile,"RAM:Football.tempcup",'r') then do
  515.             do while ~eof(datafile)
  516.                line = readln(datafile)
  517.                if line ~= "" then do
  518.                   ii = ii + 1
  519.                   say " "right(ii,2)") "line
  520.                end
  521.             end
  522.             close(datafile)
  523.          end
  524.          else do
  525.             say
  526.             say st_error
  527.             say
  528.             say st_txtj
  529.             exit
  530.          end
  531.          address command 'delete >NIL: RAM:Football.tempcup'
  532.       end
  533.    end
  534.    say
  535.    say
  536.    say
  537.    say
  538.    say
  539.    say
  540.    say
  541. end
  542. say "-------------------------------------------------------------------------------"
  543. say st_txtk
  544. say st_txtl
  545. say st_txtm
  546. say st_txtn
  547. say st_txto
  548. say st_txtp
  549.  
  550. exit
  551.  
  552. /* Routine ----------------------------------------------------------- */
  553.  
  554. format_perf:
  555. ARG fstrg,counter
  556.  
  557. ptemp = ''
  558. i = 1
  559. j = 1
  560. do while i <= counter
  561.    ptemp = insert(substr(fstrg,j,1),ptemp,i,1)
  562.    i = i + 1
  563.    j = j + 1
  564.    if i < counter then do
  565.       ptemp = insert(".",ptemp,i,1)
  566.       i = i + 1
  567.    end
  568. end
  569. ptemp = strip(ptemp)
  570. return
  571.  
  572. /* ------------------------------------------------------------------- */